var vm = new Vue({
    el: "#sel",
    data: {
        list: []
    },mounted(){
        $.get("htz/role/selChoice",{token:1},function (data) {
            var da = data;
            vm.list = da.obj;
            layui.use(['table','layer','form'], function(){
                var table = layui.table;
                var layer = layui.layer;
                $.each(data.obj, function (index, item) {
                    $('#sel').append(new Option(item.roleName, item.id));
                })
                layui.form.render("select");
                table.render({
                    elem: '#test'
                    ,url:'htz/user/select'
                    ,where: {token:1}
                    ,toolbar: '#toolbarDemo',
                    parseData: function(res) { //res 即为原始返回的数据
                        return {
                            "code": 0, //解析接口状态
                            "msg": "", //解析提示文本
                            "count": res.obj.total, //解析数据长度
                            "data": res.obj.list //解析数据列表
                        };
                    }

                    ,cols: [[
                        {field:'id', width:100, title: '员工ID', sort: true}
                        ,{field:'userName', width:120, title: '姓名'}
                        ,{field:'loginName', width:120, title: '用户名'}
                        ,{field:'password', width:120, title: '密码'}
                        ,{field:'headFileName', width:120, height:120, title: '头像',templet:function (obj) {
                                return "<img src=\"http://192.168.2.80:5050/images/wms/Avatar/"+obj.headFileName+"\" alt=\"头像\" width='50px' height='50px'>"
                            }}
                        ,{field:'roleName', width:120, title: '职位'}
                        ,{field:'phone', width:120, title: '联系电话'}
                        // ,{field:'city', width:80, title: '城市'}
                        // ,{field:'sign', title: '签名', minWidth: 100}
                        // ,{field:'experience', width:80, title: '积分', sort: true}
                        // ,{field:'score', width:80, title: '评分', sort: true}
                        // ,{field:'classify', width:80, title: '职业'}
                        // ,{field:'wealth', width:135, title: '财富', sort: true}
                        ,{ title:'操作', toolbar: '#barDemo', width:120}
                    ]]
                    ,page: true
                });
                layui.$("#add").on('click',function () {
                    layer.open({
                        type: 2,
                        area: ['600px','350px'],
                        content: 'staff_add.html',
                        success:function (layero,index) {
                            var iframe = window['layui-layer-iframe'+index];
                            // iframe.sele();
                        }
                    })
                })
                layui.$("#look").on('click',function () {
                    relod();
                })
                table.on('tool(test)', function(obj){
                    var data = obj.data; //获取选中行状态
                    if (obj.event==='del') {
                        var layer = layui.layer;
                        layer.confirm('真的删除行么', function(index){
                            $.post("htz/user/userDel",{id:data.id,token:1},function (data) {
                                if (data.obj>0){
                                    layer.msg("删除成功！")
                                }else {
                                    layer.msg("删除失败！")
                                }
                            })
                        });
                    }else if (obj.event==='edit') {
                        var layer = layui.layer;
                        layer.open({
                            type: 2,
                            area: ['600px','350px'],
                            content: 'staff_upd.html',
                            success:function (layero,index) {
                                var iframe = window['layui-layer-iframe'+index]
                                iframe.tes(data);
                            }
                        })
                    }
                })
                layui.$("#look").on('click',function () {
                    relod();
                })
                //头工具栏事件
                table.on('toolbar(test)', function(obj){
                    var checkStatus = table.checkStatus(obj.config.id); //获取选中行状态
                    switch(obj.event){
                        case 'getCheckData':
                            var data = checkStatus.data;  //获取选中行数据
                            if (data!=""){
                                layer.open({
                                    type:2,
                                    area:["600px","400px"],
                                    content:"staff_jurisdiction.html"
                                })
                            }else {
                                layer.alert("请选择一个员工")
                            }
                            // layer.alert(JSON.stringify(data));

                            break;
                    };
                });
            });
        })
    }
})
function relod() {
    layui.use('table', function() {
        var table = layui.table;
        table.reload('test', {
            page: {
                curr: 1 //重新从第一页开始
            }, where: {
                userName: $("#name").val(),
                roleId: $("#sel").val()
            }
        })
    })
}
layui.use('element', function () {
    var element = layui.element; //导航的hover效果、二级菜单等功能，需要依赖element模块
    element.render();
    setTimeout(function () {
        element.render();
    }, 300)
});